import request from "@/utils/request";
import type { RoleListResponseData, PermissionListResponseData } from "./type";
import type { RoleData } from "../user/type";
enum API {
    GET_ROLE_LIST = "/admin/acl/role",
    ADD_ROLE_URL = "/admin/acl/role/save",
    UPDATE_ROLE_URL = "/admin/acl/role/update",
    GET_ALL_PERMISSION_URL = "/admin/acl/permission/toAssign",
    ASSIGN_PERMISSION_URL = "/admin/acl/permission/doAssign",
    DELETE_ROLE_URL = "/admin/acl/role/remove",
}
//获取角色列表
export const getAllRoleList = (page: number, limit: number, roleName: string) => request.get<any, RoleListResponseData>(API.GET_ROLE_LIST+`/${page}/${limit}?roleName=${roleName}`)
//添加或修改角色
export const addorupdateRole = (data: RoleData) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATE_ROLE_URL, data)
    } else {
        return request.post<any, any>(API.ADD_ROLE_URL, data)
    }
}
//获取所有权限列表
export const getAllPermissionList = (roleId: number) => request.get<any, PermissionListResponseData>(API.GET_ALL_PERMISSION_URL + `/${roleId}`)
//分配权限
export const assignPermission = (roleId: number, permissionId: number[]) => request.post<any, any>(API.ASSIGN_PERMISSION_URL + `?roleId=${roleId}&permissionId=${permissionId}`)
//删除角色
export const deleteRole = (roleId: number) => request.delete<any, any>(API.DELETE_ROLE_URL + `/${roleId}`)
